package com.qf.sy2103.ssm.Util;

import com.qf.sy2103.ssm.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

//定义拦截器
public class Myintercept implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();

        User user = (User) session.getAttribute("user");

        if (Objects.isNull(user)){
//            request.getRequestDispatcher("/User/login.jsp").forward(request,response);
            response.sendRedirect("/User/login.html");
            return false;
        }
//        request.getRequestDispatcher("/User/find.jsp").forward(request,response);
//        response.sendRedirect("/User/find.jsp");
        return true;
    }
}
